package client;

import javax.swing.JPanel;

import metier.modele.Figure;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.LinkedList;

/**
 * Le Canvas
 * @author Quentin, Vincent, Charlie
 *
 */
public class JCanvas extends JPanel {


	private static final long serialVersionUID = 3129326811023178098L;

	private Color fg, bg;
	private Gestionnaire_Client gc;
	private LinkedList<Figure> list;
	public boolean inEdit = false;

	/**
	 * Constructeur
	 * @param gc
	 * @param larg
	 * @param haut
	 * @param list
	 */
	public JCanvas(Gestionnaire_Client gc, int larg, int haut, LinkedList<Figure> list) {
		this.gc = gc;
		this.list = list;
		setBackground(Color.white);
	}


	public LinkedList<Figure> getList() {
		return list;
	}

	public void setList(LinkedList<Figure> list) {
		this.list = list;
	}

	public Color getCurrentFg() {
		return fg;
	}

	public Color getCurrentBg() {
		return bg;
	}

	public void setCurrentFg(Color c) {
		fg = c;
	}

	public void setCurrentBg(Color c) {
		bg = c;
	}

	/**
	 * Repaint du composant
	 */
	public void paintComponent(Graphics g)
	{
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
		super.paintComponent(g2);
		for (int i = 0; i < list.size(); i++)
		{
			((Figure) list.get(i)).tracer(g2, gc.isCouleursVraies(), inEdit, list.get(i).getOwner().getColor());
		}
	}
	
	public void setAllFigureStatus(int status)
	{
		for (Figure f : list) {
			f.setStatus(status);
		}
	}
	
}